﻿<?php

    //优化初始化
    include('init.php');
    
	//给id获取数组值
	$id =$_GET['id'];
	
	
	if(!empty($_POST)){
		
		
		$title = $_POST['title'];//取编辑标题数据
		$type = $_POST['type'];//取编辑类型数据
		$author = $_POST['author'];//取编辑作者数据
		$content = $_POST['content'];//取编辑状态数据
		$status = $_POST['status'];//取编辑状态数据
	
	//查询数据表的语句
	$sql = "update `news` set `title`='$title',`type`='$type',`author`='$author',`content`='$content',
	        `status`='$status' where `id`=$id";
	
	mysqli_query($link, $sql);
	
	$row = mysqli_affected_rows($link);
	
	if($row>0){
		//echo '<script>alert("编辑成功");</script>';die;
		header('location:news_list.php');
	}else{
		echo '<script>("编辑失败");<script>';die;
	}
	}
	
	
	//编写数据
	$sql = "select * from `news` where id=$id";
	
	//执行上述查询语句
	$result = mysqli_query($link, $sql);
	
	//该函数是将查询到的数据转换成数组格式
	$data = mysqli_fetch_assoc($result);
	
//	print_r($data);
	
	
	
	
	
	
	   
    //加载新闻添加页视图
    include ('view/layout.html');

?>
